package com.ruoyi.pm.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.pubfun.IdWorker;
import com.ruoyi.framework.util.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.pm.mapper.ExcPortHeaderMapper;
import com.ruoyi.pm.domain.ExcPortHeader;
import com.ruoyi.pm.service.IExcPortHeaderService;

/**
 * 接口HeaderService业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-16
 */
@Service
public class ExcPortHeaderServiceImpl implements IExcPortHeaderService 
{
    @Autowired
    private ExcPortHeaderMapper excPortHeaderMapper;

    /**
     * 查询接口Header
     * 
     * @param id 接口Header主键
     * @return 接口Header
     */
    @Override
    public ExcPortHeader selectExcPortHeaderById(Long id)
    {
        return excPortHeaderMapper.selectExcPortHeaderById(id);
    }

    /**
     * 查询接口Header
     *
     * @param portId 接口主键
     * @param field 参数
     * @return 接口Header
     */
    @Override
    public ExcPortHeader selectByPortIdAndField(Long portId,String field){
        return excPortHeaderMapper.selectByPortIdAndField(portId,field);
    }

    /**
     * 查询接口Header列表
     * 
     * @param excPortHeader 接口Header
     * @return 接口Header
     */
    @Override
    public List<ExcPortHeader> selectExcPortHeaderList(ExcPortHeader excPortHeader)
    {
        return excPortHeaderMapper.selectExcPortHeaderList(excPortHeader);
    }

    /**
     * 新增接口Header
     * 
     * @param excPortHeader 接口Header
     * @return 结果
     */
    @Override
    public int insertExcPortHeader(ExcPortHeader excPortHeader)
    {
        excPortHeader.setId(IdWorker.getId());
        excPortHeader.setCreateBy(LoginUserUtil.getSysUser().getUserName());
        excPortHeader.setCreateTime(DateUtils.getNowDate());
        excPortHeader.setUpdateBy(LoginUserUtil.getSysUser().getUserName());
        excPortHeader.setUpdateTime(DateUtils.getNowDate());
        ExcPortHeader portHeader = excPortHeaderMapper.selectByPortIdAndField(excPortHeader.getPortId(), excPortHeader.getField());
        if(StringUtils.isNotNull(portHeader)) {
            throw new RuntimeException("该参数已存在不允许重复添加");
        }
        return excPortHeaderMapper.insertExcPortHeader(excPortHeader);
    }

    /**
     * 修改接口Header
     * 
     * @param excPortHeader 接口Header
     * @return 结果
     */
    @Override
    public int updateExcPortHeader(ExcPortHeader excPortHeader)
    {
        excPortHeader.setUpdateBy(LoginUserUtil.getSysUser().getUserName());
        excPortHeader.setUpdateTime(DateUtils.getNowDate());
        return excPortHeaderMapper.updateExcPortHeader(excPortHeader);
    }


    /**
     * 通过接口ID删除接口Header
     *
     * @param portId 接口主键
     * @return 结果
     */
    @Override
    public int deleteExcPortHeaderByPortId(Long portId){
        return excPortHeaderMapper.deleteExcPortHeaderByPortId(portId);
    }

    /**
     * 批量删除接口Header
     * 
     * @param ids 需要删除的接口Header主键
     * @return 结果
     */
    @Override
    public int deleteExcPortHeaderByIds(Long[] ids)
    {
        return excPortHeaderMapper.deleteExcPortHeaderByIds(ids);
    }

    /**
     * 删除接口Header信息
     * 
     * @param id 接口Header主键
     * @return 结果
     */
    @Override
    public int deleteExcPortHeaderById(Long id)
    {
        return excPortHeaderMapper.deleteExcPortHeaderById(id);
    }
}
